﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace KINLO.UI.Main.Converter
{
    public class LeakHuntingResultConverter : IValueConverter
    { 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ///界面测漏结果直接显示OK，已经跟熊工确定PLC目前没有设置该值可以读取，如果失败PLC会自动NG排出，不会影响
            //return "OK";
            try
            {
                if (value is null)
                {
                    return DependencyProperty.UnsetValue; ;
                }

                int count;
                if (int.TryParse(value.ToString(), out count))
                {
                    switch (count)
                    {
                        case 1: 
                            return "OK";
                        default:
                            return "NG";
                    }
                }
                else
                {
                    return DependencyProperty.UnsetValue; ;
                }
            }
            catch (Exception ex)
            { 
                return DependencyProperty.UnsetValue; ;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        } 
    }
}
